#include <stdio.h>
#include <time.h>

// 计算输入日期与今天的天数差并打印结果
void howfartoday_4() {
    int year, month, day;
    printf("请输入日期 (年 月 日，空格分隔): ");
    if (scanf("%d %d %d", &year, &month, &day) != 3) {
        printf("输入格式错误。\n");
        return;
    }

    time_t now_t = time(NULL);
    struct tm now_tm = *localtime(&now_t);

    // 获取今天日期（不含时间）
    now_tm.tm_hour = 0;
    now_tm.tm_min = 0;
    now_tm.tm_sec = 0;
    time_t today = mktime(&now_tm);

    // 构造输入日期的 tm 结构
    struct tm input_tm = {0};
    input_tm.tm_year = year - 1900;
    input_tm.tm_mon = month - 1;
    input_tm.tm_mday = day;
    input_tm.tm_hour = 0;
    input_tm.tm_min = 0;
    input_tm.tm_sec = 0;

    time_t input_time = mktime(&input_tm);

    if (input_time == (time_t)(-1)) {
        printf("输入日期无效。\n");
        return;
    }

    double diff_sec = difftime(input_time, today);
    int diff_days = (int)(diff_sec / (60 * 60 * 24));

    if (diff_days == 0) {
        printf("%d-%02d-%02d 就是今天。\n", year, month, day);
    } else if (diff_days > 0) {
        printf("%d-%02d-%02d 比今天晚 %d 天。\n", year, month, day, diff_days);
    } else {
        printf("%d-%02d-%02d 比今天早 %d 天。\n", year, month, day, -diff_days);
    }
}
